package br.com.aerusc.gui.components;

import com.vaadin.data.Property;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.Table;

public class BooleanColumnGenerator implements Table.ColumnGenerator {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
    public Component generateCell(Table source, Object itemId, Object columnId) {
        Property prop = source.getItem(itemId).getItemProperty(columnId);
        if((prop != null) && (prop.getType().equals(Boolean.class) || prop.getType().equals(boolean.class))) {
            CheckBox check = new CheckBox(null, (Boolean) prop.getValue());
            return check;
        }
        else {
            return null;
        }
    }
}

